﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CH03_04
{
    class CH03_04
    {
        static void Main(string[] args)
        {
            /*
             * 定义变量:
             * iStudents:用于统计学生人数;
             * tempScore:接收每次输入成绩;
             * maxScore、minScore:最大成绩和最小成绩;
             */
            int iStudents = 0;
            int tempScore;
            int maxScore = 0, minScore = 0;
            // 统计各成绩区间内的人数;
            int score0To59 = 0, score60To69 = 0, score70To79 = 0, score80To89 = 0, score90To100 = 0;

            Console.WriteLine("--------学生成绩统计----------");
            Console.WriteLine("统计要求:学生成绩正确的区间为0～100,\n" + "        如果输入的成绩不在此区间中,可以选择退出统计!");
            Console.WriteLine();

        loop: Console.WriteLine("请输入学生成绩:");
            string strScore = Console.ReadLine();
            if (strScore == null)
            {
                return;
            }

            tempScore = int.Parse(strScore);

            if ((tempScore < 0) || (tempScore > 100))
            {
                Console.WriteLine("你输入的分数不对,选择是(Y)退出还是继续(N)");
                string strSelect = Console.ReadLine();

                if (strSelect == "N")
                {
                    goto loop;
                }
                else
                {
                    // 输出统计信息;
                    Console.WriteLine("--------学生成绩统计信息输出----------");
                    Console.WriteLine("全班共{0:d}人,其中最高成绩{1:f2}," + "最低成绩{2:f2}", iStudents, maxScore, minScore);
                    Console.WriteLine("成绩区间90～100的人数有{0:d}人," + "所占比例为:{1:f2}%", score90To100, score90To100 * 100 / iStudents);
                    Console.WriteLine("成绩区间80～89的人数有{0:d}人," + "所占比例为:{1:f2}%", score80To89, score80To89 * 100 / iStudents);
                    Console.WriteLine("成绩区间70～79的人数有{0:d}人," + "所占比例为:{1:f2}%", score70To79, score70To79 * 100 / iStudents);
                    Console.WriteLine("成绩区间60～69的人数有{0:d}人," + "所占比例为:{1:f2}%", score60To69, score60To69 * 100 / iStudents);
                    Console.WriteLine("成绩区间0～59的人数有{0:d}人," + "所占比例为:{1:f2}%", score0To59, score0To59 * 100 / iStudents);
                    Console.ReadLine();
                }
            }
            else
            {
                // 统计学生人数;
                iStudents++;
                if (iStudents == 1)
                {
                    maxScore = tempScore;
                    minScore = tempScore;
                }
                else
                {
                    // 修正最大与最小成绩;
                    if (maxScore < tempScore)
                    {
                        maxScore = tempScore;
                    }
                    if (minScore > tempScore)
                    {
                        minScore = tempScore;
                    }
                }
                // 接收成绩所在区间的人数;
                int temp = tempScore / 10;
                switch (temp)
                {
                    case 10:
                    case 9:
                        Console.WriteLine("成绩优秀");
                        score90To100++;
                        break;
                    case 8:
                        Console.WriteLine("成绩良好");
                        score80To89++;
                        break;
                    case 7:
                        Console.WriteLine("成绩中等");
                        score70To79++;
                        break;
                    case 6:
                        Console.WriteLine("成绩及格");
                        score60To69++;
                        break;
                    default:
                        Console.WriteLine("成绩不及格");
                        score0To59++;
                        break;
                }
            }
            goto loop;
        }
    }
}
